package edu.hm.swe2;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Persistence;

import edu.hm.swe2.domain.Lagergut;
import edu.hm.swe2.domain.Lagerplatz;

public class JPADemo {

	public static void main(String[] args) {

		EntityManager emgr = Persistence.createEntityManagerFactory("jpademo").createEntityManager();
		
		emgr.getTransaction().begin();
	
		Lagerplatz lp = new Lagerplatz();
		lp.setId(100);
		lp.setHalle(1111);
		lp.setRegal("R999");
		
		emgr.persist(lp);
		
		List<Lagergut> result = 
			emgr.createQuery("select object(l) from Lagergut l", Lagergut.class).getResultList();
		
		emgr.getTransaction().commit();
		emgr.close();
		
		for(Lagergut tmp : result) {
			System.out.println(tmp.getArtikel() + ", " + tmp.getLagerplatz().getHalle());
		}
		
		

	}
	
}
